<script setup>
import { loginApi } from '@/api/user';
import router from '@/router';
import { ElMessage } from 'element-plus';
import { ref } from 'vue';


const loginForm = ref({
  username: '',
  password: ''
})

const login = async()=>{
    const result = await loginApi(loginForm.value)
    if(result.code == 1){
        ElMessage.success('登录成功')
        localStorage.setItem("userInfo",JSON.stringify(result.data))
        router.push('/')
    }else{
        ElMessage.error(result.msg)
    }
}
</script>

<template>
  <div class="common-layout">
    <el-container>
      <el-main>
        <div class="login-container">
          <div class="login">
            <el-form :model="loginForm" label-width="120px">
              <el-form-item style="margin-left: -65px;" label="用户名">
                <el-input v-model="loginForm.username" placeholder="请输入用户名" />
              </el-form-item>
              <el-form-item style="margin-left: -65px;" label="密码">
                <el-input type="password" v-model="loginForm.password" placeholder="请输入密码" />
              </el-form-item>
              <el-button type="primary" style="width: 100%;" @click="login">登录</el-button>
            </el-form>
          </div>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<style scoped>
.common-layout {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.el-container {
  background-image: url('../../assets/111.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.el-main {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: transparent;
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.login {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  border-radius: 10px;
  padding: 30px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  width: 100%;
}
</style>